<template>
  <avue-form ref="customAttributeForm" v-model="customAttributeForm" :option="option"></avue-form>
</template>
<script>
export default {
  props: ['disabled', 'customAttributeList', 'customAttributeForm'],
  data() {
    return {
      option: {
        submitBtn: false,
        emptyBtn: false,
        column: []
      }
    };
  },
  watch: {
    customAttributeForm(val) {
      this.$emit('customAttributeFormChange', val);
    }
  },
  created() {
    this._forEach(this.customAttributeList, (item) => {
      if (item.controlType === 'datatime') {
        this.option.column.push({
          label: item.lableCnName,
          prop: item.attributeKey,
          type: item.controlType,
          format: 'yyyy-MM-dd HH:mm:ss',
          valueFormat: 'yyyy-MM-dd HH:mm:ss',
          defaultValue: item.defaultValue,
          dispaly: item.enabled,
          order: item.sequence
        });
      } else {
        this.option.column.push({
          label: item.lableCnName,
          prop: item.attributeKey,
          type: item.controlType,
          value: item.defaultValue,
          dispaly: item.enabled,
          order: item.sequence
        });
      }
    });
    if (this.disabled) {
      this.$nextTick(() => {
        this.$refs.customAttributeForm.allDisabled = true;
      });
    } else {
      this.$nextTick(() => {
        this.$refs.customAttributeForm.allDisabled = false;
      });
    }
  }
};
</script>
